﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using TongCheng.API.OpenAPI.Domain;
using TongCheng.API.OpenAPI.Request;
using TongCheng.API.OpenAPI.Response;
using TongCheng.API.OpenAPI.Util;

namespace TongCheng.API.OpenAPI.Facade
{
    public static class SceneryFacade
    {
        /// <summary>
        /// 获取周边景点
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetNearbySceneryResponse GetNearbyScenery(GetNearbySceneryRequest request)
        {
            GetNearbySceneryResponse response = new GetNearbySceneryResponse();
            response.Body.sceneryList = new Domain.SceneryList();

            ITcClient client = new DefaultTcClient();
            var responseXml = client.Execute(request);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(responseXml);

            #region parse header
            response.Header.actionCode = Tools.GetXmlDocumentInnerText(doc, "header/actionCode");
            response.Header.rspType = Tools.GetXmlDocumentInnerText(doc, "header/rspType");
            response.Header.rspCode = Tools.GetXmlDocumentInnerText(doc, "header/rspCode");
            response.Header.rspDesc = Tools.GetXmlDocumentInnerText(doc, "header/rspDesc");
            response.Header.rspTime = Tools.GetXmlDocumentInnerText(doc, "header/rspTime");
            #endregion

            #region 解析scenery
            XmlNode sceneryListNode = doc.SelectSingleNode("//sceneryList");
            response.Body.sceneryList.Page = Tools.GetXmlNodeAttributeToInt(sceneryListNode, "", "page", 0);
            response.Body.sceneryList.PageSize = Tools.GetXmlNodeAttributeToInt(sceneryListNode, "", "pageSize", 0);
            response.Body.sceneryList.TotalPage = Tools.GetXmlNodeAttributeToInt(sceneryListNode, "", "totalPage", 0);
            response.Body.sceneryList.TotalCount = Tools.GetXmlNodeAttributeToInt(sceneryListNode, "", "totalCount", 0);
            response.Body.sceneryList.ImgbaseURL = Tools.GetXmlNodeAttribute(sceneryListNode, "", "imgbaseURL");
            response.Body.sceneryList.Items = new List<Scenery>();

            XmlNodeList sceneryNodes = doc.SelectNodes("//scenery");
            for (var i = 0; i < sceneryNodes.Count; i++)
            {
                var node = sceneryNodes[i];
                TongCheng.API.OpenAPI.Domain.Scenery s = new Scenery();
                s.sceneryId = Tools.GetXmlNodeInnerTextToInt(node, "id", 0);
                s.sceneryName = Tools.GetXmlNodeInnerText(node, "name");
                s.imgPath = Tools.GetXmlNodeInnerText(node, "imgpath");
                s.sceneryAddress = Tools.GetXmlNodeInnerText(node, "adress");
                s.gradeId = Tools.GetXmlNodeInnerText(node, "grade");
                s.amount = Tools.GetXmlNodeInnerText(node, "amount");
                s.amountAdvice = Tools.GetXmlNodeInnerText(node, "amountAdvice");
                s.distance = Tools.GetXmlNodeInnerText(node, "distance");
                response.Body.sceneryList.Items.Add(s);
            }
            #endregion

            return response;
        }

        /// <summary>
        /// 获取价格日历接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetPriceCalendarResponse GetPriceCalendar(GetPriceCalendarRequest request)
        {
            GetPriceCalendarResponse response = new GetPriceCalendarResponse();
            response.Body.calendarInfo = new CalendarInfo();

            ITcClient client = new DefaultTcClient();
            var responseXml = client.Execute(request);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(responseXml);

            #region parse header
            response.Header.actionCode = Tools.GetXmlDocumentInnerText(doc, "header/actionCode");
            response.Header.rspType = Tools.GetXmlDocumentInnerText(doc, "header/rspType");
            response.Header.rspCode = Tools.GetXmlDocumentInnerText(doc, "header/rspCode");
            response.Header.rspDesc = Tools.GetXmlDocumentInnerText(doc, "header/rspDesc");
            response.Header.rspTime = Tools.GetXmlDocumentInnerText(doc, "header/rspTime");
            #endregion

            #region parse calendarInfo
            response.Body.calendarInfo.sceneryId = Tools.GetXmlDocumentInnerTextToInt(doc, "body/calendarInfo/sceneryId", 0);
            response.Body.calendarInfo.sceneryName = Tools.GetXmlDocumentInnerText(doc, "body/calendarInfo/sceneryName");
            response.Body.calendarInfo.pMode = Tools.GetXmlDocumentInnerText(doc, "body/calendarInfo/pMode");
            response.Body.calendarInfo.useCard = Tools.GetXmlDocumentInnerText(doc, "body/calendarInfo/useCard");
            response.Body.calendarInfo.realName = Tools.GetXmlDocumentInnerText(doc, "body/calendarInfo/realName");
            response.Body.calendarInfo.remark = Tools.GetXmlDocumentInnerText(doc, "body/calendarInfo/remark");

            #region parse notice
            XmlNode calendarInfoNode = doc.SelectSingleNode("body/calendarInfo");
            response.Body.calendarInfo.notice = new Notice();
            response.Body.calendarInfo.notice.Items = new List<N>();
            XmlNodeList nNodeList = calendarInfoNode.SelectNodes("notice/n");
            for (int i = 0; i < nNodeList.Count; i++)
            {
                var nNode = nNodeList[i];
                Domain.N n = new N();
                n.nType = Tools.GetXmlNodeInnerTextToInt(nNode, "nType", 0);
                n.nTypeName = Tools.GetXmlNodeInnerText(nNode, "nTypeName");
                n.nInfoList = new List<Info>();

                XmlNodeList nInfoNodeList = nNode.SelectNodes("nInfo/info");
                for (int j = 0; j < nInfoNodeList.Count; j++)
                {
                    var nInfoNode = nInfoNodeList[j];
                    Info info = new Info();
                    info.nId = Tools.GetXmlNodeInnerTextToInt(nInfoNode, "nId", 0);
                    info.nName = Tools.GetXmlNodeInnerText(nInfoNode, "nName");
                    info.nContent = Tools.GetXmlNodeInnerText(nInfoNode, "nContent");
                    n.nInfoList.Add(info);
                }
                response.Body.calendarInfo.notice.Items.Add(n);
            }
            #endregion

            #region parse calendar
            response.Body.calendarInfo.calendar = new Calendar();
            response.Body.calendarInfo.calendar.Items = new List<Day>();
            XmlNodeList dayNodeList = calendarInfoNode.SelectNodes("calendar/day");
            for (int i = 0; i < dayNodeList.Count; i++)
            {
                XmlNode dayNode = dayNodeList[i];
                Domain.Day day = new Day();
                day.date = Tools.GetXmlNodeInnerText(dayNode, "date");
                day.policyId = Tools.GetXmlNodeInnerText(dayNode, "policyId");
                day.policyName = Tools.GetXmlNodeInnerText(dayNode, "policyName");
                day.pMode = Tools.GetXmlNodeInnerText(dayNode, "pMode");
                day.tcPrice = Tools.GetXmlNodeInnerText(dayNode, "tcPrice");
                day.stock = Tools.GetXmlNodeInnerText(dayNode, "stock");
                day.minT = Tools.GetXmlNodeInnerText(dayNode, "minT");
                day.maxT = Tools.GetXmlNodeInnerText(dayNode, "maxT");
                day.cash = Tools.GetXmlNodeInnerText(dayNode, "cash");
                day.remark = Tools.GetXmlNodeInnerText(dayNode, "remark");
                response.Body.calendarInfo.calendar.Items.Add(day);
            }
            #endregion


            #region parse ahead
            response.Body.calendarInfo.ahead = new Ahead();
            response.Body.calendarInfo.ahead.day = Tools.GetXmlNodeInnerText(calendarInfoNode, "ahead/day");
            response.Body.calendarInfo.ahead.time = Tools.GetXmlNodeInnerText(calendarInfoNode, "ahead/time");
            #endregion

            #endregion

            return response;
        }

        /// <summary>
        /// 获取景点详细信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetSceneryDetailResponse GetSceneryDetail(GetSceneryDetailRequest request)
        {
            GetSceneryDetailResponse response = new GetSceneryDetailResponse();
            response.Body.scenery = new Scenery();

            ITcClient client = new DefaultTcClient();
            var responseXml = client.Execute(request);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(responseXml);

            #region parse header
            response.Header.actionCode = Tools.GetXmlDocumentInnerText(doc, "header/actionCode");
            response.Header.rspType = Tools.GetXmlDocumentInnerText(doc, "header/rspType");
            response.Header.rspCode = Tools.GetXmlDocumentInnerText(doc, "header/rspCode");
            response.Header.rspDesc = Tools.GetXmlDocumentInnerText(doc, "header/rspDesc");
            response.Header.rspTime = Tools.GetXmlDocumentInnerText(doc, "header/rspTime");
            #endregion

            #region parse scenery
            XmlNode sceneryNode = doc.SelectSingleNode("response/body/scenery");
            response.Body.scenery.sceneryId = Tools.GetXmlNodeInnerTextToInt(sceneryNode, "sceneryId", 0);
            response.Body.scenery.sceneryName = Tools.GetXmlNodeInnerText(sceneryNode, "sceneryName");
            response.Body.scenery.gradeId = Tools.GetXmlNodeInnerText(sceneryNode, "grade");
            response.Body.scenery.sceneryAddress = Tools.GetXmlNodeInnerText(sceneryNode, "address");
            response.Body.scenery.cityId = Tools.GetXmlNodeAttributeToInt(sceneryNode, "city", "id", 0);
            response.Body.scenery.cityName = Tools.GetXmlNodeInnerText(sceneryNode, "city");
            response.Body.scenery.provinceId = Tools.GetXmlNodeAttributeToInt(sceneryNode, "province", "id", 0);
            response.Body.scenery.provinceName = Tools.GetXmlNodeInnerText(sceneryNode, "province");
            response.Body.scenery.intro = Tools.GetXmlNodeInnerText(sceneryNode, "intro");
            response.Body.scenery.buyNotice = Tools.GetXmlNodeInnerText(sceneryNode, "buyNotice");
            response.Body.scenery.payMode = Tools.GetXmlNodeInnerText(sceneryNode, "payMode");
            response.Body.scenery.sceneryAlias = Tools.GetXmlNodeInnerText(sceneryNode, "sceneryAlias");
            response.Body.scenery.amountAdvice = Tools.GetXmlNodeInnerText(sceneryNode, "amountAdvice");
            response.Body.scenery.lon = Tools.GetXmlNodeInnerText(sceneryNode, "lon");
            response.Body.scenery.lat = Tools.GetXmlNodeInnerText(sceneryNode, "lat");
            response.Body.scenery.ifUseCard = Tools.GetXmlNodeInnerText(sceneryNode, "ifUseCard");

            response.Body.scenery.themeList = new List<Theme>();
            Theme theme = new Theme();
            theme.themeId = Tools.GetXmlNodeInnerTextToInt(sceneryNode, "theme/themeId", 0);
            theme.themeName = Tools.GetXmlNodeInnerText(sceneryNode, "theme/themeName");
            response.Body.scenery.themeList.Add(theme);
            #endregion

            return response;
        }

        /// <summary>
        /// 获取景点图片列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetSceneryImageListResponse GetSceneryImageList(GetSceneryImageListRequest request)
        {
            GetSceneryImageListResponse response = new GetSceneryImageListResponse();
            response.Body.imageList = new ImageList();
            response.Body.extInfoOfImageList = new ExtInfoOfImageList();

            ITcClient client = new DefaultTcClient();
            var responseXml = client.Execute(request);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(responseXml);

            #region parse header
            response.Header.actionCode = Tools.GetXmlDocumentInnerText(doc, "header/actionCode");
            response.Header.rspType = Tools.GetXmlDocumentInnerText(doc, "header/rspType");
            response.Header.rspCode = Tools.GetXmlDocumentInnerText(doc, "header/rspCode");
            response.Header.rspDesc = Tools.GetXmlDocumentInnerText(doc, "header/rspDesc");
            response.Header.rspTime = Tools.GetXmlDocumentInnerText(doc, "header/rspTime");
            #endregion

            #region parse imageList
            response.Body.imageList.Items = new List<Image>();
            XmlNode imageListNode = doc.SelectSingleNode("body/imageList");
            response.Body.imageList.Page = Tools.GetXmlNodeAttributeToInt(imageListNode, "", "page", 0);
            response.Body.imageList.PageSize = Tools.GetXmlNodeAttributeToInt(imageListNode, "", "pageSize", 0);
            response.Body.imageList.TotalPage = Tools.GetXmlNodeAttributeToInt(imageListNode, "", "totalPage", 0);
            response.Body.imageList.TotalCount = Tools.GetXmlNodeAttributeToInt(imageListNode, "", "totalCount", 0);
            response.Body.imageList.Items = new List<Image>();

            XmlNodeList imageNodeList = imageListNode.SelectNodes("image");
            for (var i = 0; i < imageNodeList.Count; i++)
            {
                XmlNode imageNode = imageNodeList[i];
                Image image = new Image();
                image.imagePath = Tools.GetXmlNodeInnerText(imageNode, "imagePath");
                response.Body.imageList.Items.Add(image);
            }
            #endregion


            #region parse extInfoOfImageList
            response.Body.extInfoOfImageList.sizeCodeList = new SizeCodeList();
            response.Body.extInfoOfImageList.sizeCodeListWatermark = new SizeCodeListWatermark();
            XmlNode extInfoOfImageListNode = doc.SelectSingleNode("body/extInfoOfImageList");
            response.Body.extInfoOfImageList.imageBaseUrl = extInfoOfImageListNode.SelectSingleNode("imageBaseUrl").InnerText;

            response.Body.extInfoOfImageList.sizeCodeList.Items = new List<SizeCode>();
            XmlNodeList sizeCodeListNode = extInfoOfImageListNode.SelectNodes("sizeCodeList/sizeCode");
            for (var j = 0; j < sizeCodeListNode.Count; j++)
            {
                XmlNode sizeCodeNode = sizeCodeListNode[j];
                SizeCode sc = new SizeCode();
                sc.text = sizeCodeNode.InnerText;
                response.Body.extInfoOfImageList.sizeCodeList.Items.Add(sc);
            }

            response.Body.extInfoOfImageList.sizeCodeListWatermark.Items = new List<SizeCode>();
            XmlNodeList sizeCodeWatermarkListNode = extInfoOfImageListNode.SelectNodes("sizeCodeListWatermark/sizeCode");
            for (var j = 0; j < sizeCodeWatermarkListNode.Count; j++)
            {
                XmlNode sizeCodeWatermarkNode = sizeCodeWatermarkListNode[j];
                SizeCode sc = new SizeCode();
                sc.text = sizeCodeWatermarkNode.InnerText;
                response.Body.extInfoOfImageList.sizeCodeListWatermark.Items.Add(sc);
            }
            #endregion

            return response;
        }

        /// <summary>
        /// 获取景点列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetSceneryListResponse GetSceneryList(GetSceneryListRequest request)
        {
            GetSceneryListResponse response = new GetSceneryListResponse();
            response.Body.sceneryList = new Domain.SceneryList();
            response.Body.sceneryList.Items = new List<Scenery>();

            ITcClient client = new DefaultTcClient();
            var responseXml = client.Execute(request);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(responseXml);

            #region parse header
            response.Header.actionCode = Tools.GetXmlDocumentInnerText(doc, "header/actionCode");
            response.Header.rspType = Tools.GetXmlDocumentInnerText(doc, "header/rspType");
            response.Header.rspCode = Tools.GetXmlDocumentInnerText(doc, "header/rspCode");
            response.Header.rspDesc = Tools.GetXmlDocumentInnerText(doc, "header/rspDesc");
            response.Header.rspTime = Tools.GetXmlDocumentInnerText(doc, "header/rspTime");
            if (response.Header.rspCode == "0001") 
            {
                return response;
            }
            #endregion

            #region 解析scenery
            XmlNode sceneryListNode = doc.SelectSingleNode("//sceneryList");
            response.Body.sceneryList.Page = Tools.GetXmlNodeAttributeToInt(sceneryListNode, "", "page", 0);
            response.Body.sceneryList.PageSize = Tools.GetXmlNodeAttributeToInt(sceneryListNode, "", "pageSize", 0);
            response.Body.sceneryList.TotalPage = Tools.GetXmlNodeAttributeToInt(sceneryListNode, "", "totalPage", 0);
            response.Body.sceneryList.TotalCount = Tools.GetXmlNodeAttributeToInt(sceneryListNode, "", "totalCount", 0);
            response.Body.sceneryList.ImgbaseURL = Tools.GetXmlNodeAttribute(sceneryListNode, "", "imgbaseURL");

            XmlNodeList sceneryNodes = doc.SelectNodes("//scenery");
            for (var i = 0; i < sceneryNodes.Count; i++)
            {
                var node = sceneryNodes[i];
                TongCheng.API.OpenAPI.Domain.Scenery s = new Scenery();
                s.sceneryId = Tools.GetXmlNodeInnerTextToInt(node, "sceneryId", 0);
                s.sceneryName = Tools.GetXmlNodeInnerText(node, "sceneryName");
                s.imgPath = Tools.GetXmlNodeInnerText(node, "imgPath");
                s.sceneryAddress = Tools.GetXmlNodeInnerText(node, "sceneryAddress");
                s.scenerySummary = Tools.GetXmlNodeInnerText(node, "scenerySummary");
                s.provinceId = Tools.GetXmlNodeInnerTextToInt(node, "provinceId", 0);
                s.provinceName = Tools.GetXmlNodeInnerText(node, "provinceName");
                s.cityId = Tools.GetXmlNodeInnerTextToInt(node, "cityId", 0);
                s.cityName = Tools.GetXmlNodeInnerText(node, "cityName");
                s.commentCount = Tools.GetXmlNodeInnerTextToInt(node, "commentCount", 0);
                s.questionCount = Tools.GetXmlNodeInnerTextToInt(node, "questionCount", 0);
                s.blogCount = Tools.GetXmlNodeInnerTextToInt(node, "blogCount", 0);
                s.viewCount = Tools.GetXmlNodeInnerTextToInt(node, "viewCount", 0);
                //s.BookFlag = node.SelectSingleNode("bookFlag").InnerText;
                //s.SceneryAmount = node.SelectSingleNode("sceneryAmount").InnerText;
                //s.AdviceAmount = node.SelectSingleNode("adviceAmount").InnerText;
                s.gradeId = Tools.GetXmlNodeInnerText(node, "gradeId");
                //s.Amount = node.SelectSingleNode("amount").InnerText;
                //s.AmountAdv = node.SelectSingleNode("amountAdv").InnerText;
                //s.Lon = node.SelectSingleNode("lon").InnerText;
                //s.Lat = node.SelectSingleNode("lat").InnerText;
                //s.Distance = node.SelectSingleNode("distance").InnerText;

                s.themeList = new List<TongCheng.API.OpenAPI.Domain.Theme>();
                XmlNodeList themeList = node.SelectNodes("themeList/theme");
                for (var j = 0; j < themeList.Count; j++)
                {
                    XmlNode tNode = themeList[j];
                    Theme t = new Theme();
                    t.themeId = Tools.GetXmlNodeInnerTextToInt(tNode, "themeId", 0);
                    t.themeName = Tools.GetXmlNodeInnerText(tNode, "themeName");
                    s.themeList.Add(t);
                }

                s.suitherdList = new List<TongCheng.API.OpenAPI.Domain.Suitherd>();
                XmlNodeList suitherdList = node.SelectNodes("suitherdList/suitherd");
                for (var j = 0; j < suitherdList.Count; j++)
                {
                    XmlNode tNode = suitherdList[j];
                    Suitherd t = new Suitherd();
                    t.suitherdId = Tools.GetXmlNodeInnerTextToInt(tNode, "suitherdId", 0);
                    t.suitherdName = Tools.GetXmlNodeInnerText(tNode, "suitherdName");
                    s.suitherdList.Add(t);
                }

                s.impressionList = new List<TongCheng.API.OpenAPI.Domain.Impression>();
                XmlNodeList impressionList = node.SelectNodes("impressionList/impression");
                for (var j = 0; j < impressionList.Count; j++)
                {
                    XmlNode tNode = impressionList[j];
                    Impression t = new Impression();
                    t.impressionId = Tools.GetXmlNodeInnerTextToInt(tNode, "impressionId", 0);
                    t.impressionName = Tools.GetXmlNodeInnerText(tNode, "impressionName");
                    s.impressionList.Add(t);
                }

                s.naList = new List<TongCheng.API.OpenAPI.Domain.Na>();
                XmlNodeList naList = node.SelectNodes("naList/na");
                for (var j = 0; j < naList.Count; j++)
                {
                    XmlNode tNode = naList[j];
                    Na t = new Na();
                    t.name = Tools.GetXmlNodeInnerText(tNode, "name");
                    s.naList.Add(t);
                }
                response.Body.sceneryList.Items.Add(s);
            }
            #endregion

            return response;
        }

        /// <summary>
        /// 获取价格搜索接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetSceneryPriceResponse GetSceneryPrice(GetSceneryPriceRequest request)
        {
            GetSceneryPriceResponse response = new GetSceneryPriceResponse();
            response.Body.sceneryList = new SceneryList();

            var client = new DefaultTcClient();
            var responseXml = client.Execute(request);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(responseXml);

            #region parse header
            response.Header.actionCode = Tools.GetXmlDocumentInnerText(doc, "header/actionCode");
            response.Header.rspType = Tools.GetXmlDocumentInnerText(doc, "header/rspType");
            response.Header.rspCode = Tools.GetXmlDocumentInnerText(doc, "header/rspCode");
            response.Header.rspDesc = Tools.GetXmlDocumentInnerText(doc, "header/rspDesc");
            response.Header.rspTime = Tools.GetXmlDocumentInnerText(doc, "header/rspTime");
            #endregion

            #region 解析门票信息
            response.Body.sceneryList.Items = new List<Scenery>();
            XmlNodeList sceneryTicketNodes = doc.SelectNodes("//scenery");
            for (var i = 0; i < sceneryTicketNodes.Count; i++)
            {
                var node = sceneryTicketNodes[i];
                TongCheng.API.OpenAPI.Domain.Scenery s = new Scenery();
                s.PolicyList = new List<Policy>();
                s.noticeList = new List<Notice>();
                s.sceneryId = Tools.StrToInt(node.SelectSingleNode("sceneryId").InnerText, 0);

                var pNodeList = node.SelectNodes("policy/p");
                for (int p = 0; p < pNodeList.Count; p++)
                {
                    var pNode = pNodeList[p];
                    Policy policy = new Policy();
                    policy.policyId = Tools.GetXmlNodeInnerTextToInt(pNode, "policyId", 0);
                    policy.policyName = Tools.GetXmlNodeInnerText(pNode, "policyName");
                    policy.remark = Tools.GetXmlNodeInnerText(pNode, "remark");
                    policy.price = Tools.GetXmlNodeInnerTextToDouble(pNode, "price", 0);
                    policy.tcPrice = Tools.GetXmlNodeInnerTextToDouble(pNode, "tcPrice", 0);
                    policy.pMode = Tools.GetXmlNodeInnerTextToInt(pNode, "pMode", 0);
                    policy.gMode = Tools.GetXmlNodeInnerText(pNode, "gMode");
                    policy.minT = Tools.GetXmlNodeInnerTextToInt(pNode, "minT", 0);
                    policy.maxT = Tools.GetXmlNodeInnerTextToInt(pNode, "maxT", 0);
                    policy.dpPrize = pNode.SelectSingleNode("dpPrize").InnerText;
                    policy.orderUrl = pNode.SelectSingleNode("orderUrl").InnerText;
                    policy.realName = Tools.GetXmlNodeInnerTextToInt(pNode, "realName", 0);
                    policy.useCard = Tools.GetXmlNodeInnerTextToInt(pNode, "useCard", 0);
                    policy.ticketId = Tools.GetXmlNodeInnerTextToInt(pNode, "ticketId", 0);
                    policy.ticketName = Tools.GetXmlNodeInnerText(pNode, "ticketName");
                    policy.bDate = Tools.GetXmlNodeInnerText(pNode, "bDate");
                    policy.eDate = Tools.GetXmlNodeInnerText(pNode, "eDate");
                    policy.openDateType = Tools.GetXmlNodeInnerText(pNode, "openDateType");
                    policy.openDateValue = Tools.GetXmlNodeInnerText(pNode, "openDateValue");
                    policy.closeDate = Tools.GetXmlNodeInnerText(pNode, "closeDate");
                    s.PolicyList.Add(policy);
                }

                //var nNodeList = node.SelectNodes("notice/n");
                //for (int n = 0; n < nNodeList.Count; n++)
                //{
                //    var nNode = nNodeList[n];
                //    var notice = new Notice();

                //    s.NoticeList.Add(notice);
                //}

                var aNode = node.SelectSingleNode("ahead");
                s.ahead = new Ahead();
                if (aNode != null)
                {
                    s.ahead.day = Tools.GetXmlNodeInnerText(aNode, "day");
                    s.ahead.time = Tools.GetXmlNodeInnerText(aNode, "time");
                }

                response.Body.sceneryList.Items.Add(s);
            }
            #endregion

            return response;
        }

        /// <summary>
        /// 获取景点交通指南信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetSceneryTrafficInfoResponse GetSceneryTrafficInfo(GetSceneryTrafficInfoRequest request)
        {
            GetSceneryTrafficInfoResponse response = new GetSceneryTrafficInfoResponse();
            response.Body.scenery = new Scenery();

            ITcClient client = new DefaultTcClient();
            var responseXml = client.Execute(request);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(responseXml);

            #region parse header
            response.Header.actionCode = Tools.GetXmlDocumentInnerText(doc, "header/actionCode");
            response.Header.rspType = Tools.GetXmlDocumentInnerText(doc, "header/rspType");
            response.Header.rspCode = Tools.GetXmlDocumentInnerText(doc, "header/rspCode");
            response.Header.rspDesc = Tools.GetXmlDocumentInnerText(doc, "header/rspDesc");
            response.Header.rspTime = Tools.GetXmlDocumentInnerText(doc, "header/rspTime");
            #endregion

            #region parse scenery
            XmlNode sceneryNode = doc.SelectSingleNode("response/body/scenery");
            response.Body.scenery.sceneryId = Tools.GetXmlNodeInnerTextToInt(sceneryNode, "sceneryId", 0);
            response.Body.scenery.lon = Tools.GetXmlNodeInnerText(sceneryNode, "longitude");
            response.Body.scenery.lat = Tools.GetXmlNodeInnerText(sceneryNode, "latitude");
            response.Body.scenery.traffic = Tools.GetXmlNodeInnerText(sceneryNode, "traffic");
            #endregion

            return response;
        }
    }
}
